<template>
    <div class="contain">
        <div class="input_modal">
            <div class="input-item">
                <el-input v-model="searchWord" placeholder="请输入申请ID" class="proName"  @keyup.enter.native="search"></el-input>
                 <el-button type="primary" @click="getApplyAuthorizationList">查询申请</el-button>
            </div>
        </div>
        
        <div class="table_con">
            <el-table :data="tableData" stripe style="width: 100%">
                <el-table-column prop="applyId" label="申请ID" >
                </el-table-column>
                <el-table-column prop="voteTitle" label="投票主题" style="width: 20%">
                </el-table-column>
                <el-table-column prop="voteId" label="投票主题ID" style="width: 20%">
                </el-table-column>
                <el-table-column prop="userNickName" label="申请人昵称" style="width: 20%">
                </el-table-column>
                <el-table-column prop="userId" label="申请人ID" style="width: 20%">
                </el-table-column>
                <el-table-column prop="userTrueName" label="申请人姓名" style="width: 20%">
                </el-table-column>
                <el-table-column prop="applyWord" label="申请人口令" style="width: 20%">
                </el-table-column>
                <el-table-column prop="applyStatus" label="申请状态" style="width: 20%">
                    <template slot-scope="scope">
                         <span>{{ scope.row.applyStatus | formatStatus }}</span>
                       </template>
                </el-table-column>
                <el-table-column  prop="applyId"  label="操作" fixed="right" width='160'  v-if="actionShow">
                      <template slot-scope="scope">
                          <el-button type="primary" plain size="mini" @click="applyItem(scope.row.applyId,'SUCCESS')"  v-if='tableData[scope.$index].applyStatus == "AUDITING"'>通过</el-button>
                          <el-button type="danger" plain size="mini" @click="applyItem(scope.row.applyId,'REJECT')" v-if='tableData[scope.$index].applyStatus == "AUDITING"'>不通过</el-button>
                      </template>
                  </el-table-column>
            </el-table>
        </div>

         <div class="pagination">
             <el-pagination   @size-change="handleSizeChange"  @current-change="handleCurrentChange"       
                :current-page.sync="pageIndex"              
                :page-size="pageSize"   
                :page-sizes='[10,20,30,40]'    
                layout="sizes, prev, pager, next"       
                :total="pageCount">     
            </el-pagination>
        </div>
    </div>
</template>

<script>
let CONSTANT = require('../../constant/constant.js');
let common = require("../../common.js");
export default {
    data() {
        
        return {
            actionShow:true,
            searchWord:'',
            applyId:'',
            userId:'',
            voteId:'',
            voteTitle:'',
            voteIntroduction:'',
            userNickName:'',
            userTrueName:'',
            applyWord:'',
            applyStatus:'',
            applyStatus:'',
            statusList:[
                {value:'AUDITING', lable:'审核中'},
                {value:'SUCCESS', lable:'同意'},
                {value:'REJECT', lable:'驳回'},
            ],
            tableData:[],
            pageCount:null,
            pageIndex:1,
            pageSize:10,
            loading:true,
            dialogVisible:false,
            dialogTitle:'操作提示',
            dialogType:'camp',
            rules: {
            
            },
        }
    },
    mounted() {
        this.getApplyAuthorizationList();
    },
    methods: {
        getApplyAuthorizationList:function(){  
            let url = CONSTANT.URL.USER.FINDVOTEUSERAPPLYBYPAGE;
            let dataForm = {
               pageIndex:this.pageIndex,
               pageSize:this.pageSize
            }
            let data = {
            } ;
            if(this.searchWord != ''){
               data.searchWord = this.searchWord;
            }

            let param = JSON.stringify(data);
            this.loading = true;
            common.requestAjax(url,param,dataForm,(res)=>{
                this.loading = false;
                let data = res.data;
                console.log('分页获取申请列表',data);
                this.tableData = data.bussData;
                this.pageCount = data.pageCount*this.pageSize;
            }) 
        },
        search(e){
            if(e.keyCode == 13){
                this.pageIndex = 1;
                this.getApplyAuthorizationList();
            }
        },
        applyItem:function(applyId,status){
            // console.log('申请id---',applyId);
            // console.log('审核状态----', status);
            let confirmTip = '';
            console.log('审核状态', status);
            if(status == 'SUCCESS'){
                confirmTip = '确定审核通过?';
            }
            else{
                confirmTip = '确定审核不通过?';
            }
            this.$confirm(confirmTip, '提示', {           
                confirmButtonText: '确定',           
                cancelButtonText: '取消',           
                type: 'warning'         
            }).then(() => {           
                let  url = CONSTANT.URL.USER.UPDAPPLYSTATUS;
                let param = {
                    applyId:applyId,
                    applyStatus:status
                };
                common.requestAjax(url,param,null,(res)=>{
                    if(res.status == 200){
                        this.$message({
                            type:'SUCCESS',
                            message:'审核操作成功!'
                        });
                        this.getApplyAuthorizationList();
                    }
                    else{
                        this.$message({
                            type:'warning',
                            message:res.msg
                        })
                    }
                })      
            }).catch(() => {           
                this.$message({             
                    type: 'AUDITING',             
                    message: '已取消审核操作'           
                });                   
            });    
        },
        handleSizeChange(val) {
            this.pageSize= val;
            this.getApplyAuthorizationList(this.pageIndex);
        },
        handleCurrentChange(val) {
            this.getApplyAuthorizationList(val);
            this.pageIndex = val;
        },
        handleClose(){
            this.dialogVisible = false;
        },
    },
    filters:{
        formatStatus(value){ 
            var status = [];
            status['AUDITING'] = '审核中';
            status['SUCCESS'] = '同意';
            status['REJECT'] = '驳回';
            if(value){
                return status[value];
            }
            else{ return '--'};
         },   
    }
}
</script>

<style lang="scss" scoped>
    .contain {
         .header{
            margin: 20px 0;
            padding-bottom: 10px;
            border-bottom:1px solid #dedede; 
        }
        .input_modal {
            margin-top: 20px;
            .input-item{ 
                display: inline-block;
                margin-right: 20px;
                clear: both;
                height: 40px;
                line-height: 40px;
                .el-input,.el-button, .el-select,span{ float: left;margin-right: 10px;}
                .proName{width:200px;}
            }
        }
        .el-dialog__body{
            // padding:  10px 20px;
            .dialog-con{
                padding:0px 20px 0px 0px;
                p{  text-align: center;margin:5px 0px 20px 0px;font-size: 14px;color: #666;
                    span{
                        color: #111;font-size: 14px;
                    }
                }
            }
        }
        .table_con{
            text-align: center;
            // .el-button{
            //     display: inline-block;
            //     width: 104px;
            //     height: 30px;
            //     margin-left: 0;
            //     margin-top: 5px;
            // }
            // .el-button:nth-child(3){
            //      margin-top: 5px;
            // }
        }
        .el-pagination {
            text-align: center;
            width: 100%;
            margin-top: 60px;
        }
    }
</style>
